package com.augmented.jellybean;

import java.util.ArrayList;
import java.util.HashMap;

import com.augmented.jellybean.util.ListViewAdapter;
import com.augmented.jellybean.util.information;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class AugmentedJellybeanListScreenActivity extends Activity {
	ListView list;
	ListViewAdapter adapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.augmented_jellybean_list_screen);

		ArrayList<information> places = new ArrayList<information>();

		// Setting up button listener

		Button btnMap = (Button) findViewById(R.id.map_view);

		btnMap.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				//Starting a new Intent
				Intent nextScreen = new Intent(getApplicationContext(), AugmentedJellybeanMapScreenActivity.class);

				//Sending data to another Activity
				Log.i("Loading Map View", "SUCCESS");

				startActivity(nextScreen);
				finish();
			}
		});

		@SuppressWarnings("unchecked")
		HashMap<String, information> markerMap = (HashMap<String, information>) getIntent().getExtras().get("list_view");
		@SuppressWarnings("unchecked")
		ArrayList<String> keys = (ArrayList<String>) getIntent().getExtras().get("keys");

		for (int i = 0; i < keys.size(); i++) {
			// Adding places into a list 
			String key = keys.get(i);
			information d = markerMap.get(key);

			places.add(d);
		}

		list = (ListView)findViewById(R.id.listview);

		// Getting adapter by passing xml data ArrayList
		adapter = new ListViewAdapter(this, places);
		list.setAdapter(adapter);

		// Click event for single list row
		list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {

			}
		});
	}
}
